import pytest
from common.request_util_test import RequestUtil
from common.test_yaml_util_test import YamlUtil
import json

class Testevent:

    @pytest.mark.parametrize('eventinfo', YamlUtil().read_testcase_yaml('v24.06/resourcemanage/event/1_get_event_list.yaml'))
    def test_get_event_list(self, eventinfo, get_env_info):
        # 获取event列表接口
        baseUrl = get_env_info
        url = baseUrl + eventinfo['request']['url']
        method = eventinfo['request']['method']
        req = RequestUtil().send_request(method, url)
        assert req.status_code == eventinfo['validate'][0]['equals']['status_code']

    @pytest.mark.parametrize('eventinfo', YamlUtil().read_testcase_yaml('v24.06/resourcemanage/event/2_get_event_by_kind.yaml'))
    def test_get_event_by_kind(self, eventinfo, get_env_info):
        # 通过类型查找event
        baseUrl = get_env_info
        url = baseUrl + eventinfo['request']['url'].replace('{kind}','Pod')
        method = eventinfo['request']['method']
        req = RequestUtil().send_request(method, url)
        assert req.status_code == eventinfo['validate'][0]['equals']['status_code']

    @pytest.mark.parametrize('eventinfo', YamlUtil().read_testcase_yaml('v24.06/resourcemanage/event/3_get_event_of_namespace.yaml'))
    def test_get_event_of_namespace(self, eventinfo, get_env_info):
        # 获取某个命名空间下的event列表
        baseUrl = get_env_info
        url = baseUrl + eventinfo['request']['url'].replace('{namespace}','default')
        method = eventinfo['request']['method']
        req = RequestUtil().send_request(method, url)
        assert req.status_code == eventinfo['validate'][0]['equals']['status_code']